/**
 * Created by Administrator on 2017-6-9.
 */
$(function () {
    
    $("#submit").bind("click", function () {
        submit();
    });

    $('body').keydown(function(event){
        if(event.keyCode==13){
            submit();
        }
    });

    $("#kaptchaImage").bind("click", function () {
        chageViliCode();
    });
    
    function chageViliCode() {
        $("#imgCode").attr("src", "/getpatchcaImage");
    }

    function submit() {
        $.ajax({
            type: "POST",
            url: "/login",
            data: $("#loginForm").serialize(),
            success: function (result) {
                var data = $.parseJSON(result);
                if (data.message){
                    layer.alert(data.message,{icon:1});
                    chageViliCode();
                } else {
                    location.href = "/index" ;
                }
            },
            error: function (a,b,c) {
            }
        });
    }

});